1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module soup.Date; 26 27 private import glib.ConstructionException; 28 private import glib.MemorySlice; 29 private import glib.Str; 30 private import glib.TimeVal; 31 private import glib.c.functions; 32 private import gobject.ObjectG; 33 private import linker.Loader; 34 private import soup.c.functions; 35 public import soup.c.types; 36 37 38 /** 39 * A date and time. The date is assumed to be in the (proleptic) 40 * Gregorian calendar. The time is in UTC if @utc is %TRUE. Otherwise, 41 * the time is a local time, and @offset gives the offset from UTC in 42 * minutes (such that adding @offset to the time would give the 43 * correct UTC time). If @utc is %FALSE and @offset is 0, then the 44 * %SoupDate represents a "floating" time with no associated timezone 45 * information. 46 */ 47 public final class Date 48 { 49 /** the main Gtk struct */ 50 protected SoupDate* soupDate; 51 protected bool ownedRef; 52 53 /** Get the main Gtk struct */ 54 public SoupDate* getDateStruct(bool transferOwnership = false) 55 { 56 if (transferOwnership) 57 ownedRef = false; 58 return soupDate; 59 } 60 61 /** the main Gtk struct as a void* */ 62 protected void* getStruct() 63 { 64 return cast(void*)soupDate; 65 } 66 67 /** 68 * Sets our main struct and passes it to the parent class. 69 */ 70 public this (SoupDate* soupDate, bool ownedRef = false) 71 { 72 this.soupDate = soupDate; 73 this.ownedRef = ownedRef; 74 } 75 76 ~this () 77 { 78 if ( Linker.isLoaded(LIBRARY_SOUP[0]) && ownedRef ) 79 soup_date_free(soupDate); 80 } 81 82 83 /** 84 * the year, 1 to 9999 85 */ 86 public @property int year() 87 { 88 return soupDate.year; 89 } 90 91 /** Ditto */ 92 public @property void year(int value) 93 { 94 soupDate.year = value; 95 } 96 97 /** 98 * the month, 1 to 12 99 */ 100 public @property int month() 101 { 102 return soupDate.month; 103 } 104 105 /** Ditto */ 106 public @property void month(int value) 107 { 108 soupDate.month = value; 109 } 110 111 /** 112 * day of the month, 1 to 31 113 */ 114 public @property int day() 115 { 116 return soupDate.day; 117 } 118 119 /** Ditto */ 120 public @property void day(int value) 121 { 122 soupDate.day = value; 123 } 124 125 /** 126 * hour of the day, 0 to 23 127 */ 128 public @property int hour() 129 { 130 return soupDate.hour; 131 } 132 133 /** Ditto */ 134 public @property void hour(int value) 135 { 136 soupDate.hour = value; 137 } 138 139 /** 140 * minute, 0 to 59 141 */ 142 public @property int minute() 143 { 144 return soupDate.minute; 145 } 146 147 /** Ditto */ 148 public @property void minute(int value) 149 { 150 soupDate.minute = value; 151 } 152 153 /** 154 * second, 0 to 59 (or up to 61 in the case of leap seconds) 155 */ 156 public @property int second() 157 { 158 return soupDate.second; 159 } 160 161 /** Ditto */ 162 public @property void second(int value) 163 { 164 soupDate.second = value; 165 } 166 167 /** 168 * %TRUE if the date is in UTC 169 */ 170 public @property bool utc() 171 { 172 return soupDate.utc != 0; 173 } 174 175 /** Ditto */ 176 public @property void utc(bool value) 177 { 178 soupDate.utc = value; 179 } 180 181 /** 182 * offset from UTC 183 */ 184 public @property int offset() 185 { 186 return soupDate.offset; 187 } 188 189 /** Ditto */ 190 public @property void offset(int value) 191 { 192 soupDate.offset = value; 193 } 194 195 /** */ 196 public static GType getType() 197 { 198 return soup_date_get_type(); 199 } 200 201 /** 202 * Creates a #SoupDate representing the indicated time, UTC. 203 * 204 * Params: 205 * year = the year (1-9999) 206 * month = the month (1-12) 207 * day = the day of the month (1-31, as appropriate for @month) 208 * hour = the hour (0-23) 209 * minute = the minute (0-59) 210 * second = the second (0-59, or up to 61 for leap seconds) 211 * 212 * Returns: a new #SoupDate 213 * 214 * Throws: ConstructionException GTK+ fails to create the object. 215 */ 216 public this(int year, int month, int day, int hour, int minute, int second) 217 { 218 auto __p = soup_date_new(year, month, day, hour, minute, second); 219 220 if(__p is null) 221 { 222 throw new ConstructionException("null returned by new"); 223 } 224 225 this(cast(SoupDate*) __p); 226 } 227 228 /** 229 * Creates a #SoupDate representing a time @offset_seconds after the 230 * current time (or before it, if @offset_seconds is negative). If 231 * offset_seconds is 0, returns the current time. 232 * 233 * If @offset_seconds would indicate a time not expressible as a 234 * <type>time_t</type>, the return value will be clamped into range. 235 * 236 * Params: 237 * offsetSeconds = offset from current time 238 * 239 * Returns: a new #SoupDate 240 * 241 * Throws: ConstructionException GTK+ fails to create the object. 242 */ 243 public this(int offsetSeconds) 244 { 245 auto __p = soup_date_new_from_now(offsetSeconds); 246 247 if(__p is null) 248 { 249 throw new ConstructionException("null returned by new_from_now"); 250 } 251 252 this(cast(SoupDate*) __p); 253 } 254 255 /** 256 * Parses @date_string and tries to extract a date from it. This 257 * recognizes all of the "HTTP-date" formats from RFC 2616, all ISO 258 * 8601 formats containing both a time and a date, RFC 2822 dates, 259 * and reasonable approximations thereof. (Eg, it is lenient about 260 * whitespace, leading "0"s, etc.) 261 * 262 * Params: 263 * dateString = the date in some plausible format 264 * 265 * Returns: a new #SoupDate, or %NULL if @date_string 266 * could not be parsed. 267 * 268 * Throws: ConstructionException GTK+ fails to create the object. 269 */ 270 public this(string dateString) 271 { 272 auto __p = soup_date_new_from_string(Str.toStringz(dateString)); 273 274 if(__p is null) 275 { 276 throw new ConstructionException("null returned by new_from_string"); 277 } 278 279 this(cast(SoupDate*) __p); 280 } 281 282 /** 283 * Creates a #SoupDate corresponding to @when 284 * 285 * Params: 286 * when = a <type>time_t</type> 287 * 288 * Returns: a new #SoupDate 289 * 290 * Throws: ConstructionException GTK+ fails to create the object. 291 */ 292 public this(uint when) 293 { 294 auto __p = soup_date_new_from_time_t(when); 295 296 if(__p is null) 297 { 298 throw new ConstructionException("null returned by new_from_time_t"); 299 } 300 301 this(cast(SoupDate*) __p); 302 } 303 304 /** 305 * Copies @date. 306 * 307 * Since: 2.24 308 */ 309 public Date copy() 310 { 311 auto __p = soup_date_copy(soupDate); 312 313 if(__p is null) 314 { 315 return null; 316 } 317 318 return ObjectG.getDObject!(Date)(cast(SoupDate*) __p, true); 319 } 320 321 /** 322 * Frees @date. 323 * 324 * Since: 2.24 325 */ 326 public void free() 327 { 328 soup_date_free(soupDate); 329 ownedRef = false; 330 } 331 332 /** 333 * Gets @date's day. 334 * 335 * Returns: @date's day 336 * 337 * Since: 2.32 338 */ 339 public int getDay() 340 { 341 return soup_date_get_day(soupDate); 342 } 343 344 /** 345 * Gets @date's hour. 346 * 347 * Returns: @date's hour 348 * 349 * Since: 2.32 350 */ 351 public int getHour() 352 { 353 return soup_date_get_hour(soupDate); 354 } 355 356 /** 357 * Gets @date's minute. 358 * 359 * Returns: @date's minute 360 * 361 * Since: 2.32 362 */ 363 public int getMinute() 364 { 365 return soup_date_get_minute(soupDate); 366 } 367 368 /** 369 * Gets @date's month. 370 * 371 * Returns: @date's month 372 * 373 * Since: 2.32 374 */ 375 public int getMonth() 376 { 377 return soup_date_get_month(soupDate); 378 } 379 380 /** 381 * Gets @date's offset from UTC. 382 * 383 * Returns: @date's offset from UTC. If soup_date_get_utc() 384 * returns %FALSE but soup_date_get_offset() returns 0, that means the 385 * date is a "floating" time with no associated offset information. 386 * 387 * Since: 2.32 388 */ 389 public int getOffset() 390 { 391 return soup_date_get_offset(soupDate); 392 } 393 394 /** 395 * Gets @date's second. 396 * 397 * Returns: @date's second 398 * 399 * Since: 2.32 400 */ 401 public int getSecond() 402 { 403 return soup_date_get_second(soupDate); 404 } 405 406 /** 407 * Gets @date's UTC flag 408 * 409 * Returns: %TRUE if @date is UTC. 410 * 411 * Since: 2.32 412 */ 413 public int getUtc() 414 { 415 return soup_date_get_utc(soupDate); 416 } 417 418 /** 419 * Gets @date's year. 420 * 421 * Returns: @date's year 422 * 423 * Since: 2.32 424 */ 425 public int getYear() 426 { 427 return soup_date_get_year(soupDate); 428 } 429 430 /** 431 * Determines if @date is in the past. 432 * 433 * Returns: %TRUE if @date is in the past 434 * 435 * Since: 2.24 436 */ 437 public bool isPast() 438 { 439 return soup_date_is_past(soupDate) != 0; 440 } 441 442 /** 443 * Converts @date to a string in the format described by @format. 444 * 445 * Params: 446 * format = the format to generate the date in 447 * 448 * Returns: @date as a string 449 */ 450 public string toString(SoupDateFormat format) 451 { 452 auto retStr = soup_date_to_string(soupDate, format); 453 454 scope(exit) Str.freeString(retStr); 455 return Str.toString(retStr); 456 } 457 458 /** 459 * Converts @date to a <type>time_t</type>, assumming it to be in 460 * UTC. 461 * 462 * If @date is not representable as a <type>time_t</type>, it will be 463 * clamped into range. (In particular, some HTTP cookies have 464 * expiration dates after "Y2.038k" (2038-01-19T03:14:07Z).) 465 * 466 * Returns: @date as a <type>time_t</type> 467 */ 468 public uint to_time_t() 469 { 470 return soup_date_to_time_t(soupDate); 471 } 472 473 /** 474 * Converts @date to a #GTimeVal. 475 * 476 * Deprecated: Do not use #GTimeVal, as it's not Y2038-safe. 477 * 478 * Params: 479 * time = a #GTimeVal structure in which to store the converted time. 480 * 481 * Since: 2.24 482 */ 483 public void toTimeval(out TimeVal time) 484 { 485 GTimeVal* outtime = sliceNew!GTimeVal(); 486 487 soup_date_to_timeval(soupDate, outtime); 488 489 time = new TimeVal(outtime, true); 490 } 491 }